package fy.uap.operatorImpl;

import java.sql.Connection;
import java.sql.PreparedStatement;
import java.sql.ResultSet;
import java.util.ArrayList;
import java.util.List;

import org.apache.commons.logging.Log;
import org.apache.commons.logging.LogFactory;
import fy.config.FyConfig;
import fy.form.listen.dao.MyOrgManager;
import fy.form.listen.operate.AForm_Save_Operator;
import fy.form.listen.set.OA_UAPAccountContrast;
import fy.uap.bean.ProviderImportFormBean;
import fy.uap.dao.ContentMapping;
import fy.uap.dao.CopySrmProviderImportFormDao;
import fy.util.DBUtil;
import fy.util.MyUtil;



public class SrmProviderImportFormOperator extends AForm_Save_Operator {
	private static Log log = LogFactory.getLog(SrmProviderImportFormOperator.class);
	private ProviderImportFormBean pifb = new ProviderImportFormBean();

	private List<String> type1List = new ArrayList<String>();
	private List<String> type2List = new ArrayList<String>();
	private List<String> type3List = new ArrayList<String>();

	private List<String> typeName1List = new ArrayList<String>();
	private List<String> typeName2List = new ArrayList<String>();
	private List<String> typeName3List = new ArrayList<String>();

	private List<String> companyIDList = new ArrayList<String>();
	private String senderCompany;

	private ApptitudeReader apptitudeReader = new ApptitudeReader();

	// 是否制造部导入 true表示由总办导入，选择了多个制造部
	private boolean sign = false;

	private long memberID;

	public String getFormName() {
		return "供应商导入审批表";
	}

	// 弃用
	private boolean setSupplierType() {
		try {
			int size = 0;
			if ((size = type1List.size()) == type2List.size()) {
				if (size == type3List.size()) {
					if (size > 0) {
						for (int i = 0; i < size; i++) {
							String type = type3List.get(i);
							String name = typeName3List.get(i);
							if (type == null || "".equals(type)) {
								type = type2List.get(i);
								name = typeName2List.get(i);
								if (type == null || "".equals(type)) {
									type = type1List.get(i);
									name = typeName1List.get(i);
								}

							}
							pifb.addSupplyRange(type);
							pifb.setSupplyRangeMap(type, name);
						}
						return true;
					}
				}
			}
		} finally {
			type1List = null;
			type2List = null;
			type3List = null;

			typeName1List = null;
			typeName2List = null;
			typeName3List = null;
		}
		return false;

	}

	public boolean save() {
		

		ProviderMessageManager pmm = new ProviderMessageManager();
		pmm.setMemberID(memberID);
		// 验证工号是否存在，可省略
		/*
		 * if (pmm.checkMemberIDIsExists(pifb.getMemberCode())) {
		 * 
		 * if (setSupplierType()) { if (!sign) { // 供应商共享 if
		 * (!setCompany(senderCompany))
		 * 
		 * if (companyIDList.indexOf(senderCompany) == -1)
		 * companyIDList.add(senderCompany); }
		 * 
		 * pifb.setCompanyIDList(companyIDList); // pifb.printFields();
		 * 
		 * SrmProviderImportFormDao pifd = new SrmProviderImportFormDao();
		 * 
		 * pifd.setProviderImportFormBean(pifb);
		 */
		for(int  temp=0;companyIDList.size()>temp;temp++) {
			log.info("!!!"+temp+companyIDList.get(temp));
		}
		
		 pifb.setcompanyList(companyIDList);
		 
		pifb.setSupplyRangeList(this.typeName3List);
		CopySrmProviderImportFormDao pifd = new CopySrmProviderImportFormDao();
		pifd.setProviderImportFormBean(pifb);
	pifd.setUapAccountList();
		
		pifd.save();
		return true;
	}
	// pifd.setUapAccountList();

	// pifd.setApptitudeBeans(apptitudeReader.getApptitude());

	/*
	 * if (pifd.save()) { if (pifd.getFailRangeList() != null ||
	 * pifd.getUnchangingRangeList() != null) { StringBuilder sb = new
	 * StringBuilder().append("《")
	 * .append(super.formBean.getFlowExport().getFlowTitle()).append(
	 * "》导入UAP存在未导入的项，单据编号：") .append(pifb.getNumber()).append("。");
	 * 
	 * if (pifd.getFailRangeList() != null && pifd.getFailRangeList().size() >
	 * 0) { List<RangeBean> list = pifd.getFailRangeList();
	 * sb.append("\n导入失败项："); for (int i = 0, size = list.size(); i < size; i++)
	 * { sb.append("\n")
	 * .append(OA_UAPAccountContrast.getAccountNameByUapID(list.get(i).
	 * getPk_corp()));
	 * sb.append("   ").append(pifb.getSupplyRangeName(list.get(i).
	 * getPk_invclass())) .append("；"); } }
	 * 
	 * if (pifd.getUnchangingRangeList() != null &&
	 * pifd.getUnchangingRangeList().size() > 0) { List<RangeBean> list =
	 * pifd.getUnchangingRangeList(); sb.append("\n未变更状态项："); for (int i = 0,
	 * size = list.size(); i < size; i++) { sb.append("\n")
	 * .append(OA_UAPAccountContrast.getAccountNameByUapID(list.get(i).
	 * getPk_corp()));
	 * sb.append("   ").append(pifb.getSupplyRangeName(list.get(i).
	 * getPk_invclass())) .append("；"); ; } }
	 * 
	 * pmm.sendMessage(sb.toString());
	 * LogWriter.writeLog(MyUtil.getRealPath(this.getClass()), sb.toString());
	 * 
	 * } if (!pifd.isWriteAptitudeSuccess()) { StringBuilder sb = new
	 * StringBuilder().append("《")
	 * .append(super.formBean.getFlowExport().getFlowTitle())
	 * .append("》导入供应商资质发生异常，请手工录入。单据编号：").append(pifb.getNumber()).append("。");
	 * pmm.sendMessage(sb.toString());
	 * LogWriter.writeLog(MyUtil.getRealPath(this.getClass()), sb.toString()); }
	 * 
	 * if (!pifd.isWriteToErpSuccess()) { String msg = new
	 * StringBuilder().append("《")
	 * .append(super.formBean.getFlowExport().getFlowTitle()).append(
	 * "》导入ERP发生异常，单据编号：")
	 * .append(pifb.getNumber()).append("。请联系集团采购部相关人员，手工导入。").toString();
	 * pmm.sendMessage(msg);
	 * LogWriter.writeLog(MyUtil.getRealPath(this.getClass()), msg);
	 * 
	 * } return true; } else { String msg = new
	 * StringBuilder().append("《").append(super.formBean.getFlowExport().
	 * getFlowTitle()) .append("》导入UAP和ERP失败，单据编号：").append(pifb.getNumber())
	 * .append("。原因：写入UAP数据库发生异常。请联系集团采购部相关人员，手工导入。").toString();
	 * pmm.sendMessage(msg);
	 * LogWriter.writeLog(MyUtil.getRealPath(this.getClass()), msg); } } else {
	 * String msg = new
	 * StringBuilder().append("《").append(super.formBean.getFlowExport().
	 * getFlowTitle()) .append("》导入UAP和ERP失败，单据编号：").append(pifb.getNumber())
	 * .append("。原因：获取到的需要导入的供货范围为空。请联系集团采购部相关人员，手工导入。").toString();
	 * pmm.sendMessage(msg);
	 * LogWriter.writeLog(MyUtil.getRealPath(this.getClass()), msg); } } else {
	 * String msg = new
	 * StringBuilder().append("《").append(super.formBean.getFlowExport().
	 * getFlowTitle())
	 * .append("》写入UAP和ERP失败，单据编号：").append(pifb.getNumber()).append(
	 * "。原因：填单人员工号为空。").toString(); pmm.sendMessage(msg);
	 * LogWriter.writeLog(MyUtil.getRealPath(this.getClass()), msg); } return
	 * false; }
	 */

	@Override
	protected void parseOtherField_FirstStep(com.seeyon.v3x.services.flow.bean.FlowExport flowExport) {
		pifb.setApplicationTime(MyUtil.getNowStr());
		memberID = flowExport.getFlowCreatePerson().getId();
		pifb.setMemberCode(MyOrgManager.getInstance().getMemberByID(memberID).getCode());
		log.info("memberCode:" + MyOrgManager.getInstance().getMemberByID(memberID).getCode());

	}

	@Override
	protected void parseValueExport(com.seeyon.v3x.services.form.bean.ValueExport ve) {
		String name = ve.getDisplayName();
		String value = ve.getValue();
		String temp = null;
		ContentMapping content = new ContentMapping();
		try {

		if ("供应商查询".equals(name)) {
				temp = value;
				log.info("1 在供货范围内" + temp);
			} else if ("供货范围分类3".equals(name)) {
				typeName3List.add(value);// 类别
			} else if ("供应商名称".equals(name)) {
				pifb.setProviderName(MyUtil.replaceXMLString(value));
			} else if ("供应商编码".equals(name)) {
				pifb.setProviderCode(MyUtil.replaceXMLString(value));
			} else if ("导入制造部名称".equals(name)) {
				sign = true;
			//	log.info("@@@@@@@@@@@@@");
				pifb.setSupplyCompany(value);
				log.info("导入制造部名称name" + value);
			} else if ("单据编号".equals(name)) {
				pifb.setNumber(value);
			} else if ("日期".equals(name)) {
				pifb.setApplicationDate(MyUtil.getDate(value));
			} else if ("处理意见".equals(name)) {
				pifb.setOption(MyUtil.replaceXMLString(value));
			} else if ("是否福耀关联方".equals(name)) {
				pifb.setCvenfygl(MyUtil.strIsNotNull(value) ? value : "否");
			} else if ("新增原因".equals(name)) {
				pifb.setReason(MyUtil.replaceXMLString(value));
			}else if ("FYWD".equals(name)) {
				log.info("111value"+value);
				if(value.equals("1")) {
					log.info("FYWD"+getUapUnitName("1004"));
					this.companyIDList.add(getUapUnitName("1004"));
				}
			} else if ("FYTJ".equals(name)) {
				if(value.equals("1")) {
					log.info("FYTJ"+getUapUnitName("1037"));
					this.companyIDList.add(getUapUnitName("1037"));
				}
				
			} else if ("FYGZ".equals(name)) {
				if(value.equals("1")) {
				log.info("FYGZ"+getUapUnitName("1006"));
				this.companyIDList.add(getUapUnitName("1006"));
				}
			} else if ("FYSH".equals(name)) {
				if(value.equals("1")) {
					log.info("FYSH"+getUapUnitName("1007"));
					this.companyIDList.add(getUapUnitName("1007"));
			}
			
			} else if ("SHKC".equals(name)) {
				if(value.equals("1")) {
				log.info("SHKC"+getUapUnitName("1008"));
				this.companyIDList.add(getUapUnitName("1008"));
				}
			} else if ("FYHB".equals(name)) {
				if(value.equals("1")) {
				log.info("FYHB"+getUapUnitName("1009"));
				this.companyIDList.add(getUapUnitName("1009"));
				}
			} else if ("FYCQ".equals(name)) {
				if(value.equals("1")) {
				log.info("FYCQ"+getUapUnitName("1010"));
				this.companyIDList.add(getUapUnitName("1010"));
				}
			} else if ("FYWS".equals(name)) {
				if(value.equals("1")) {
				log.info("FYWS"+getUapUnitName("1011"));
				this.companyIDList.add(getUapUnitName("1011"));
				}
			} else if ("FYBJ".equals(name)) {
				if(value.equals("1")) {
				log.info("FYBJ"+getUapUnitName("1012"));
				this.companyIDList.add(getUapUnitName("1012"));
				}
			} else if ("FYCC".equals(name)) {
				if(value.equals("1")) {
				log.info("FYCC"+getUapUnitName("1013"));
				this.companyIDList.add(getUapUnitName("1013"));
				}
			} else if ("BSCC".equals(name)) {
				if(value.equals("1")) {
				log.info("BSCC"+getUapUnitName("1014"));
				this.companyIDList.add(getUapUnitName("1014"));
				}
			} else if ("FYJX".equals(name)) {
				if(value.equals("1")) {
				log.info("FYJX"+getUapUnitName("1015"));
				this.companyIDList.add(getUapUnitName("1015"));
				}
			} else if ("FYSZ".equals(name)) {
				if(value.equals("1")) {
				log.info("FYSZ"+getUapUnitName("1041"));
				this.companyIDList.add(getUapUnitName("1041"));
				}
			} else if ("FYZZ".equals(name)) {
				if(value.equals("1")) {
				log.info("FYZZ"+getUapUnitName("1023"));
				this.companyIDList.add(getUapUnitName("1023"));
				}
			} else if ("FYJT".equals(name)) {
				if(value.equals("1")) {
				log.info("FYJT"+getUapUnitName("1002"));
				this.companyIDList.add(getUapUnitName("1002"));
				}
			} else if ("FYSY".equals(name)) {
				if(value.equals("1")) {
				log.info("FYSY"+getUapUnitName("1028"));
				this.companyIDList.add(getUapUnitName("1028"));
				}
			}else if ("FY".equals(name)) {
				if(value.equals("1")) {
				log.info("FY"+getUapUnitName("1025"));
				this.companyIDList.add("福耀玻璃工业集团股份有限公司（万达）");
				}
			}else if (temp.equals("0")==true) {
				log.info("0 不在供货范围内" + temp);

			if ("供货范围分类1值".equals(name)) {
					type1List.add(value);
				} else if ("供货范围分类2值".equals(name)) {
					type2List.add(value);
				} else if ("供货范围分类3值".equals(name)) {
					type3List.add(value);
				} else if ("供货范围分类1".equals(name)) {
					typeName1List.add(value);
				} else if ("供货范围分类2".equals(name)) {
					typeName2List.add(value);
				} else if ("同类供应商".equals(name)) {
					pifb.setSimilarSuppliers(MyUtil.replaceXMLString(value));
				} else if ("企业地址".equals(name)) {
					pifb.setAddress(MyUtil.replaceXMLString(value));
				} else if ("联系人".equals(name)) {
					pifb.setLinkman(MyUtil.replaceXMLString(value));
				} else if ("供货周期".equals(name)) {
					pifb.setSupplyCycle(MyUtil.replaceXMLString(value));
				} else if ("结算银行".equals(name)) {
					pifb.setCvenbank(MyUtil.replaceXMLString(value));
				} else if ("发货地址".equals(name)) {
					pifb.setSupplyAddress(MyUtil.replaceXMLString(value));
				} else if ("电话号码".equals(name)) {
					pifb.setTel(MyUtil.replaceXMLString(value));
				} else if ("发票税码".equals(name)) {
					pifb.setCpurbillcode(MyUtil.replaceXMLString(value));
				} else if ("银行账号".equals(name)) {
					pifb.setBankAccount(MyUtil.replaceXMLString(value));
				} else if ("税务登记号".equals(name)) {
					pifb.setTaxRegister(MyUtil.replaceXMLString(value));
				} else if ("传真号码".equals(name)) {
					pifb.setFax(MyUtil.replaceXMLString(value));
				} else if ("物流方式".equals(name)) {// 原 物流方式PK
					// pifb.setCouttype(MyUtil.replaceXMLString(value));
					pifb.setCouttype(content.queryCouttypeSelectOption(MyUtil.replaceXMLString(value)));

				} else if ("币种".equals(name)) {// 原 币种PK
					// pifb.setCmoneytype(MyUtil.replaceXMLString(value));
					pifb.setCmoneytype(content.queryMoneyTypeSelectOption(MyUtil.replaceXMLString(value)));
				} else if ("质量体系".equals(name)) {
					pifb.setQualitySystem(MyUtil.replaceXMLString(value));
				} else if ("邮编".equals(name)) {
					pifb.setPostCode(MyUtil.replaceXMLString(value));
				} else if ("企业类型".equals(name)) {// 原 企业类型PK
					// pifb.setCompanyType(MyUtil.replaceXMLString(value));
					pifb.setCompanyType(content.queryCompanyTypeSelectOption(MyUtil.replaceXMLString(value)));
				} else if ("付款条件".equals(name)) {
					pifb.setCcuspaycond(MyUtil.replaceXMLString(value));
				} else if ("属性".equals(name)) {
					pifb.setProperty(MyUtil.replaceXMLString(value));
				} else if ("电子邮箱".equals(name)) {
					pifb.setEmail(MyUtil.replaceXMLString(value));
				} else if ("价格条款".equals(name)) {
					pifb.setCcontent(MyUtil.replaceXMLString(value));
				} else if ("处理意见值".equals(name)) {
					pifb.setOption(MyUtil.replaceXMLString(value));
				} else if ("是否在供应商名录内".equals(name)) {
					pifb.setProviderIsExist(value);
				} else if ("单位选择器".equals(name)) {
					senderCompany = OA_UAPAccountContrast.getUapAccountID(value);
				}  else if ("开户银行".equals(name)) {
					// pifb.setcVenBankMemo(MyUtil.replaceXMLString(value));
					pifb.setcVenBankMemo(content.queryCvenbankSelectOption(MyUtil.replaceXMLString(value)));
				} else if ("银行开户名".equals(name)) {
					pifb.setBankAccountName(MyUtil.replaceXMLString(value));
				} else if ("银行代码".equals(name)) {
					pifb.setBankCode(MyUtil.replaceXMLString(value));
				} else if ("企业类别".equals(name)) {
					pifb.setQylb(MyUtil.replaceXMLString(value));
				} else if ("注册资金".equals(name)) {
					pifb.setZczj(MyUtil.replaceXMLString(value));
				} else if ("成立时间".equals(name)) {
					pifb.setClsj(MyUtil.replaceXMLString(value));
				} else if ("职工总人数".equals(name)) {
					pifb.setZgrs(MyUtil.replaceXMLString(value));
				} else if ("经营场所".equals(name)) {
					pifb.setJycs(MyUtil.replaceXMLString(value));
				} else if ("法人代表".equals(name)) {
					pifb.setFrdb(MyUtil.replaceXMLString(value));
				} else if ("法人代表身份证".equals(name)) {
					pifb.setFrdbsfz(MyUtil.replaceXMLString(value));
				} else if ("年销售额".equals(name)) {
					pifb.setNxse(MyUtil.replaceXMLString(value));
				}/*else if ("FYWD".equals(name)) {
					log.info("111value"+value);
					if(value.equals(1)) {
						log.info("FYWD"+getUapUnitName("1004"));
						this.companyIDList.add(getUapUnitName("1004"));
					}
				} else if ("FYTJ".equals(name)) {
					if(value.equals(1)) {
						log.info("FYTJ"+getUapUnitName("1037"));
						this.companyIDList.add(getUapUnitName("1037"));
					}
					
				} else if ("FYGZ".equals(name)) {
					if(value.equals(1)) {
					log.info("FYGZ"+getUapUnitName("1006"));
					this.companyIDList.add(getUapUnitName("1006"));
					}
				} else if ("FYSH".equals(name)) {
					if(value.equals(1)) {
						log.info("FYSH"+getUapUnitName("1007"));
						this.companyIDList.add(getUapUnitName("1007"));
				}
				
				} else if ("SHKC".equals(name)) {
					if(value.equals(1)) {
					log.info("SHKC"+getUapUnitName("1008"));
					this.companyIDList.add(getUapUnitName("1008"));
					}
				} else if ("FYHB".equals(name)) {
					if(value.equals(1)) {
					log.info("FYHB"+getUapUnitName("1009"));
					this.companyIDList.add(getUapUnitName("1009"));
					}
				} else if ("FYCQ".equals(name)) {
					if(value.equals(1)) {
					log.info("FYCQ"+getUapUnitName("1010"));
					this.companyIDList.add(getUapUnitName("1010"));
					}
				} else if ("FYWS".equals(name)) {
					if(value.equals(1)) {
					log.info("FYWS"+getUapUnitName("1011"));
					this.companyIDList.add(getUapUnitName("1011"));
					}
				} else if ("FYBJ".equals(name)) {
					if(value.equals(1)) {
					log.info("FYBJ"+getUapUnitName("1012"));
					this.companyIDList.add(getUapUnitName("1012"));
					}
				} else if ("FYCC".equals(name)) {
					if(value.equals(1)) {
					log.info("FYCC"+getUapUnitName("1013"));
					this.companyIDList.add(getUapUnitName("1013"));
					}
				} else if ("BSCC".equals(name)) {
					if(value.equals(1)) {
					log.info("BSCC"+getUapUnitName("1014"));
					this.companyIDList.add(getUapUnitName("1014"));
					}
				} else if ("FYJX".equals(name)) {
					if(value.equals(1)) {
					log.info("FYJX"+getUapUnitName("1015"));
					this.companyIDList.add(getUapUnitName("1015"));
					}
				} else if ("FYSZ".equals(name)) {
					if(value.equals(1)) {
					log.info("FYSZ"+getUapUnitName("1041"));
					this.companyIDList.add(getUapUnitName("1041"));
					}
				} else if ("FYZZ".equals(name)) {
					if(value.equals(1)) {
					log.info("FYZZ"+getUapUnitName("1023"));
					this.companyIDList.add(getUapUnitName("1023"));
					}
				} else if ("FYJT".equals(name)) {
					if(value.equals(1)) {
					log.info("FYJT"+getUapUnitName("1002"));
					this.companyIDList.add(getUapUnitName("1002"));
					}
				} else if ("FYSY".equals(name)) {
					if(value.equals(1)) {
					log.info("FYSY"+getUapUnitName("1028"));
					this.companyIDList.add(getUapUnitName("1028"));
					}
				}*/

				log.info("开户银行：" + content.queryCvenbankSelectOption(MyUtil.replaceXMLString(value))
						+ "单位选择器senderCompany：'" + senderCompany + "企业类型："
						+ content.queryCompanyTypeSelectOption(MyUtil.replaceXMLString(value)) + "币种："
						+ content.queryMoneyTypeSelectOption(MyUtil.replaceXMLString(value)) + "物流方式：'"
						+ content.queryCouttypeSelectOption(MyUtil.replaceXMLString(value)));
			}

			/*
			 * else if
			 * (OA_UAPAccountContrast.getUapShortNameList().indexOf(name) != -1)
			 * { if ("1".equals(value)) { String uapAccount =
			 * OA_UAPAccountContrast.getUapAccountIDByUAPShortName(name);
			 * System.out.println("11111"+uapAccount); if
			 * (!setCompany(uapAccount)) { if (uapAccount != null &&
			 * companyIDList.indexOf(uapAccount) == -1) {
			 * companyIDList.add(uapAccount); } } } } else {
			 * apptitudeReader.read(name, value); }
			 */
		} catch (Exception e) {

			e.printStackTrace();
		}
	}

	private boolean setCompany(String uapAccount) {
		// 福清万达/巴士/包边/福耀四公司供应商导入共享
		if ("1004".equals(uapAccount) || "1005".equals(uapAccount)) {
			if (companyIDList.indexOf("1004") == -1) {
				companyIDList.add("1004");
			}
			if (companyIDList.indexOf("1005") == -1) {
				companyIDList.add("1005");
			}
			if (companyIDList.indexOf("1024") == -1) {
				companyIDList.add("1024");
			}
			if (companyIDList.indexOf("1025") == -1) {
				companyIDList.add("1025");
			}
			return true;
		} else if ("1013".equals(uapAccount) || "1014".equals(uapAccount)) {
			// 长春轿车/ 巴士公司供应商导入共享
			if (companyIDList.indexOf("1013") == -1) {
				companyIDList.add("1013");
			}
			if (companyIDList.indexOf("1014") == -1) {
				companyIDList.add("1014");
			}
			return true;
		} else if ("1006".equals(uapAccount) || "1026".equals(uapAccount)) {
			// 广州汽车玻璃/广州佛山汽车玻璃导入共享
			if (companyIDList.indexOf("1006") == -1) {
				companyIDList.add("1006");
			}
			if (companyIDList.indexOf("1026") == -1) {
				companyIDList.add("1026");
			}
			return true;
		} else if ("1009".equals(uapAccount) || "1032".equals(uapAccount)) {
			// 湖北/武汉荆门导入共享
			if (companyIDList.indexOf("1032") == -1) {
				companyIDList.add("1032");
			}
			if (companyIDList.indexOf("1009") == -1) {
				companyIDList.add("1009");
			}
			return true;
		} else if ("1012".equals(uapAccount)) {
			// 北京 导入保定
			if (companyIDList.indexOf("1036") == -1) {
				companyIDList.add("1036");
			}
			return true;
		}
		return false;
	}
	//根据pk_corp获取组织名
	public String getUapUnitName(String pk_corp) {
				//System.out.println("11111111");
				String unitname = null;
				Connection conns;
				PreparedStatement pst = null;
				ResultSet rs = null;
				try {
					conns = DBUtil.connect(FyConfig.getUAP_DB_CONFIG());
						pst = conns
								.prepareStatement("select unitname  from bd_corp where pk_corp=?");
						pst.setString(1,pk_corp);
						rs = pst.executeQuery();
						while (rs.next()) {
							unitname = rs.getString(1);
							//System.out.println(pk_corp);
						}
				} catch (Exception e) {
					e.printStackTrace();
				} finally {
					DBUtil.close(rs);
					DBUtil.close(pst);
				}
				return unitname;
			}
}
